package pratice.leetcode;

import org.junit.Test;

/**
 * @author 吴宇亮 on 2019/5/6 0006 上午 11:35
 */
public class IntRange {

    @Test
    public void test1(){
        Integer.valueOf("1111111111111111");
    }

    @Test
    public void test2(){
        System.out.println(Integer.valueOf("001")); //输出1
        System.out.println(Integer.valueOf("-001")); //输出-1
    }

    public int reverse(int x) {
        String value = String.valueOf(Math.abs(x));
        StringBuilder sb = new StringBuilder(value);

        sb = sb.reverse();
        if(x < 0){
            sb.insert(0, "-");
        }

        try {
            return Integer.valueOf(sb.toString());
        }catch (NumberFormatException e){
            return 0;
        }
    }
}
